package android.meetingatsb

import android.content.Intent
import android.meetingatsb.common.Dating
import android.meetingatsb.common.Requirement
import android.meetingatsb.common.User
import android.meetingatsb.widget.RequirementFragment
import android.os.Bundle
import android.support.v7.app.AppCompatActivity
import android.widget.Button
import android.widget.TextView

class DatingActivity : AppCompatActivity() {
    lateinit var currDating: Dating
    lateinit var selfRequirement: Requirement
    lateinit var matchUser: User

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        getData()
        setFragment()
        setContentView(R.layout.activity_dating)
        setData()
        setMap()
        setListener()
    }

    private fun setListener() {
        findViewById<Button>(R.id.dating_cancel).setOnClickListener {
            currDating.status = "未完成"
            intent.setClass(this, MainActivity::class.java)
            intent.flags = Intent.FLAG_ACTIVITY_CLEAR_TOP
            startActivity(intent)
        }
        findViewById<Button>(R.id.dating_finished).setOnClickListener {
            currDating.status = "待评价"
            intent.setClass(this, MainActivity::class.java)
            intent.flags = Intent.FLAG_ACTIVITY_CLEAR_TOP
            startActivity(intent)
        }
    }


    private fun setFragment() {
        val fragTran = fragmentManager.beginTransaction()
        val requirementFragment = RequirementFragment()
        fragTran.replace(R.id.user_requirement_fragment, requirementFragment)
        val bundle = Bundle()
        bundle.putParcelable("requirement", selfRequirement)
        requirementFragment.arguments = bundle
        fragTran.commit()
    }


    private fun getData() {
        currDating = intent.extras.getParcelable("dating")
        matchUser = intent.extras.getParcelable("matchUser")
        selfRequirement = intent.extras.getParcelable("selfRequirement")
    }

    private fun setData() {
        (findViewById<TextView>(R.id.dating_type)).text = currDating.type
        (findViewById<TextView>(R.id.dating_detail)).text = currDating.detail
        (findViewById<TextView>(R.id.dating_status)).text = currDating.status

    }

    private fun setMap() {
    }
}